﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using NT.EduABP.Configuration;
using NT.EduABP.Web;

namespace NT.EduABP.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class EduABPDbContextFactory : IDesignTimeDbContextFactory<EduABPDbContext>
    {
        public EduABPDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<EduABPDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder(), addUserSecrets: true);

            EduABPDbContextConfigurer.Configure(builder, configuration.GetConnectionString(EduABPConsts.ConnectionStringName));

            return new EduABPDbContext(builder.Options);
        }
    }
}